package cn.kongwg.mbp.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;
import sun.net.www.MeteredStream;

import java.time.LocalDateTime;
import java.util.Date;

/**
 * @author kongwg
 * @create 2021-03-24 15:17
 */
@Slf4j
@Component
public class MyDateObjectHandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        log.info("insert fill .....");
//        this.strictUpdateFill(metaObject, "createTime", () -> LocalDateTime.now(), LocalDateTime.class); // 起始版本 3.3.3(推荐)
        this.setFieldValByName("createTime", new Date(), metaObject);
        this.setFieldValByName("updateTime", new Date(), metaObject);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        log.info("update fill .....");
        this.setFieldValByName("updateTime", new Date(), metaObject);
    }
}
